package com.controller;

import com.page.GenericPage;
import com.po.AdvertisementPO;
import com.po.AdvertisementBindPO;
import com.po.AdvertisementQueryPO;
import com.po.AdvertisementUpdatePo;
import com.result.Result;
import com.service.AdvertiesementService;
import com.vo.AdvertisementVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="AdvertisementApi",tags={"GuangGao"})
@CrossOrigin
@RestController
@RequestMapping("/advertisement")
public class AdvertisementController {


//    查询命名为： query,修改是modify，删除时remove

    @Autowired
    private AdvertiesementService advertiesementService;


    @ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<AdvertisementVO> save(@RequestBody AdvertisementPO advertisementPO) {
        return advertiesementService.save(advertisementPO);
    }

    @ApiOperation(value = "删除", httpMethod = "POST", notes = "删除")
    @RequestMapping(value = "/removeAllByIds", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Result removeAllByIds(@RequestBody List<Long> ids) {
        return advertiesementService.removeAllByIds(ids);
    }

    @ApiOperation(value = "更新", httpMethod = "POST", notes = "更新")
    @RequestMapping(value = "/update", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result modify(@RequestBody AdvertisementUpdatePo advertisementUpdatePo) {

        return advertiesementService.modify(advertisementUpdatePo);
    }

    @ApiOperation(value = "根据id查询", httpMethod = "GET", notes = "根据id查询")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public Result<AdvertisementVO> selectById(@RequestParam("id") Long id) {
        return advertiesementService.queryById(id);
    }

    @ApiOperation(value = "条件查询", httpMethod = "POST", notes = "条件查询")
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<GenericPage<AdvertisementVO>> queryAll(@RequestBody AdvertisementQueryPO advertisementQueryPO) {
        return advertiesementService.queryAll(advertisementQueryPO);
    }




    /**
     * 发布广告
     *
     */
    @ApiOperation(value = "发布广告", httpMethod = "GET", notes = "发布广告")
    @RequestMapping(value = "/publishByAdvertisementId", method = RequestMethod.GET)
    public Result<Boolean> publishByAdvertisementId(@RequestParam("id") Long id) {
        return advertiesementService.publishByAdvertisementId(id);
    }


    @ApiOperation(value = "根据SN查询", httpMethod = "GET", notes = "根据SN查询")
    @RequestMapping(value = "/queryAdvertisementBySn", method = RequestMethod.GET)
    public Result<AdvertisementVO> queryAdvertisementBySn(@RequestParam("sn") String sn) {
        return advertiesementService.queryAdvertisementBySn(sn);
    }
}
